<?php
/**
 * 留言本控制
 * Enter description here ...
 * @author Code.404
 *
 */
import('@.ORG.FAC');
class GuestbookAction extends BaseAction {
	private $_mes_type = 0;
	function _init(){
		
		if(isset($_REQUEST['mes_type'])){
			try{
				$this->_mes_type = FAC::F($_REQUEST['mes_type'] ,FAC::INT);
			}catch (Exception $e){
				exit($e->getMessage());
			}
			$this->assign('mes_type',$this->_mes_type);
		}
	}
	/**
	 * 获取消息列表
	 * Enter description here ...
	 */
	function guestMessageList(){
		if(isset($_REQUEST['keyword_title'])){
			$map['title'] = array('like' , '%' . FAC::F($_REQUEST['keyword_title'] , FAC::STRING) . '%') ;
			$this->assign('keyword_title' ,  FAC::F($_REQUEST['keyword_title'] , FAC::STRING));
		}
		if(isset($_REQUEST['keyword_user'])){
			$map['guest_user'] = array('like' , '%' . FAC::F($_REQUEST['keyword_user'] , FAC::STRING) . '%')  ;
			$this->assign('keyword_user' ,FAC::F($_REQUEST['keyword_user'] , FAC::STRING));
		}
		if(isset($_REQUEST['keyword_tel'])){
			$map['guest_tel'] = array('like' , '%' . FAC::F($_REQUEST['keyword_tel'] , FAC::STRING) . '%') ;
			$this->assign('keyword_tel' ,  FAC::F($_REQUEST['keyword_tel'] , FAC::STRING));
		}

		$map['is_audit'] = $this->_mes_type;

		$this->_list(D('Guestbook'), $map , 'is_read asc , leave_time desc , id desc');
		
		$this->display();
	}
	/**
	 * 查看信息内容，如果未读，则置为已读
	 * Enter description here ...
	 */
	function viewMessage(){
		$message = D('Guestbook')->getMessageById($_REQUEST['id'] );
		echo '<div style="margin:10px; line-height:20px ; text-indent:20px; overflow:auto">' . $message['message'] . '</div>';
	}
	/**
	 * 删除留言
	 * Enter description here ...
	 */
	function deleteMessage(){
		$this->delete('Guestbook', $_GET['id'] ,'', '', 1);
	}
	/**
	 * 修改留言审核状态
	 * Enter description here ...
	 */
	function auditMessage(){
		$this->_one_touch_action('Guestbook', 'changeAudit',$_GET['id'] ,'', '' ,1);
	}
}